package com.fsnbigdata.service.impl;
import com.fsnbigdata.service.api.ParkDistrictService;
import org.springframework.roo.addon.layers.service.annotations.RooServiceImpl;
import com.fsnbigdata.domain.Park;
import com.fsnbigdata.domain.ParkDistrict;
import com.fsnbigdata.domain.ParkDistrictOrganism;
import com.fsnbigdata.repository.ParkDistrictRepository;
import com.fsnbigdata.service.api.ParkDistrictOrganismService;
import io.springlets.data.domain.GlobalSearch;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * = ParkDistrictServiceImpl
 *
 * TODO Auto-generated class documentation
 *
 */
@RooServiceImpl(service = ParkDistrictService.class)
@Service
@Transactional(readOnly = true)
public class ParkDistrictServiceImpl implements ParkDistrictService {

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    private ParkDistrictOrganismService parkDistrictOrganismService;

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    private ParkDistrictRepository parkDistrictRepository;

    /**
     * TODO Auto-generated constructor documentation
     *
     * @param parkDistrictRepository
     * @param parkDistrictOrganismService
     */
    @Autowired
    public ParkDistrictServiceImpl(ParkDistrictRepository parkDistrictRepository, @Lazy ParkDistrictOrganismService parkDistrictOrganismService) {
        setParkDistrictRepository(parkDistrictRepository);
        setParkDistrictOrganismService(parkDistrictOrganismService);
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return ParkDistrictRepository
     */
    public ParkDistrictRepository getParkDistrictRepository() {
        return parkDistrictRepository;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param parkDistrictRepository
     */
    public void setParkDistrictRepository(ParkDistrictRepository parkDistrictRepository) {
        this.parkDistrictRepository = parkDistrictRepository;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return ParkDistrictOrganismService
     */
    public ParkDistrictOrganismService getParkDistrictOrganismService() {
        return parkDistrictOrganismService;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param parkDistrictOrganismService
     */
    public void setParkDistrictOrganismService(ParkDistrictOrganismService parkDistrictOrganismService) {
        this.parkDistrictOrganismService = parkDistrictOrganismService;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param parkDistrict
     * @param organismsToAdd
     * @return ParkDistrict
     */
    @Transactional
    public ParkDistrict addToOrganisms(ParkDistrict parkDistrict, Iterable<ParkDistrictOrganism> organismsToAdd) {
        parkDistrict.addToOrganisms(organismsToAdd);
        return getParkDistrictRepository().save(parkDistrict);
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param parkDistrict
     * @param organismsToRemove
     * @return ParkDistrict
     */
    @Transactional
    public ParkDistrict removeFromOrganisms(ParkDistrict parkDistrict, Iterable<Long> organismsToRemove) {
        List<ParkDistrictOrganism> organisms = getParkDistrictOrganismService().findAll(organismsToRemove);
        parkDistrict.removeFromOrganisms(organisms);
        return getParkDistrictRepository().save(parkDistrict);
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param entity
     * @return ParkDistrict
     */
    @Transactional
    public ParkDistrict save(ParkDistrict entity) {
        return getParkDistrictRepository().save(entity);
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param id
     * @return ParkDistrict
     */
    public ParkDistrict findOne(Long id) {
        return getParkDistrictRepository().findOne(id);
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param id
     * @return ParkDistrict
     */
    public ParkDistrict findOneForUpdate(Long id) {
        return getParkDistrictRepository().findOneDetached(id);
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param ids
     * @return List
     */
    public List<ParkDistrict> findAll(Iterable<Long> ids) {
        return getParkDistrictRepository().findAll(ids);
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param park
     * @param globalSearch
     * @param pageable
     * @return Page
     */
    public Page<ParkDistrict> findByPark(Park park, GlobalSearch globalSearch, Pageable pageable) {
        return getParkDistrictRepository().findByPark(park, globalSearch, pageable);
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param park
     * @return Long
     */
    public long countByPark(Park park) {
        return getParkDistrictRepository().countByPark(park);
    }

    @Override
    public List<Long> getIdsByCity(String city) {
        return getParkDistrictRepository().getIdsByName(city);
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return Class
     */
    public Class<ParkDistrict> getEntityType() {
        return ParkDistrict.class;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return Class
     */
    public Class<Long> getIdType() {
        return Long.class;
    }
}
